﻿#include <iostream>
using namespace std;

class Fruit {
public:
    Fruit() {}
    ~Fruit() {}
    virtual void ripe() = 0;
};
class apple : public Fruit{
public:
    apple() {}
    virtual void ripe() {
        cout << "苹果成熟了" << endl;
    }
};

class bananer : public Fruit{
public:
    bananer() {}
    virtual void ripe() {
        cout << "香蕉成熟了" << endl;
    }
};

class Factory{
public:
    virtual Fruit* createFactory() = 0;
    virtual ~Factory() {}
};

class appleFactory :public Factory {
public:
    virtual Fruit* createFactory() {
        cout << "苹果加工" << endl;
        return new apple;
    }
};
class bananerFactory :public Factory {
    virtual Fruit* createFactory() {
        return new bananer;
    }
};

//设计模式之工厂模式
class juice_manufacturing
{
private:
    Factory *factory;
public:
    juice_manufacturing(Factory* factory) {
        this->factory = factory;
    }
    void useRawMaterial() {   
        factory->createFactory()->ripe();//多态new
    }
    ~juice_manufacturing() {
        delete factory;
    }
};

void main()
{
    Factory* fac = new appleFactory;
    juice_manufacturing j(fac);
    j.useRawMaterial();
}
